package com.example.dbsample.web;

import com.example.dbsample.model.entity.SysDictData;
import com.example.dbsample.model.http.LujsResponse;
import com.example.dbsample.service.business.SysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

import static com.example.dbsample.util.net.WebUtils.getIpAddr;

@Api(tags = "模拟接口")
@Slf4j
@RestController
@RequestMapping("/mock")
public class MockMyBatisPlusController extends BaseRest {

    @Value("#{'${split.urls}'.split(',')}")
    private List<String> splitUrls;

    @Autowired
    SysDictDataService sysDictDataService;

    @ApiOperation("模拟查询MyBatisPlus接口")
    @PostMapping("/mockQueryByMyBatisPlus")
    public LujsResponse<SysDictData> mockQueryByMyBatisPlus() {

        List<String> strList = Arrays.asList("123", "345", "127", "119", "345");
        log.info("xxx: {}", strList);

        SysDictData sysDictData = sysDictDataService.querySysDictDataEntity();

        // 本地请求，会展示：127.0.0.1
        System.out.println(getIpAddr());

        return LujsResponse.ofSuccess(sysDictData);
    }
}
